package com.sbxBase.controller;

import com.common.entity.Result;
import com.common.entity.sbxBase.AppStore;
import com.common.validations.NotRequiredField;
import com.common.validations.RequiredField;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import com.sbxBase.service.AppStoreService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Set;

@RestController
@RequestMapping("/appStoreManager")
@Api(tags = "app商城管理")
public class AppStoreManagerController {

    @Resource
    private AppStoreService appStoreService;

    /**
     * 新增
     */
    @PostMapping
    @ApiOperation("新增商城app")
    public Result saveStoreApp(@RequestBody @Validated(value = RequiredField.class) AppStore appStore) {
        appStoreService.saveStoreApp(appStore);
        return Result.success();
    }

    @ApiOperation("删除商城app")
    @DeleteMapping
    public Result deleteAppStoreById(@ApiParam("应用id") @RequestParam Set<String> appIds) {
        appStoreService.deleteAppStoreById(appIds);
        return Result.success();
    }

    @GetMapping
    @ApiOperation("分页查询商城app")
    public Result getAppStorePage(@Validated(value = NotRequiredField.class) AppStore appStore,
                                  @ApiParam("起始页") @RequestParam(defaultValue = "1") Integer pageIndex,
                                  @ApiParam("每页大小") @RequestParam(defaultValue = "10") Integer pageSize) {

        return Result.page(appStoreService.getAppStorePage(appStore, pageIndex, pageSize));
    }

    @PutMapping
    @ApiOperation("商城app信息修改")
    public Result updateStoreApp(@RequestBody @Validated(NotRequiredField.class) AppStore appStore) {
        appStoreService.updateStoreApp(appStore);
        return Result.success();
    }
}
